package com.dog.modules.system.web;


import com.alibaba.fastjson2.JSON;
import com.dog.modules.infra.api.dto.request.AccessLogCreateReqDTO;
import com.dog.modules.infra.api.fegin.AccessLogClient;
import com.dog.modules.upms.dto.request.UserReqDto;
import com.dog.modules.upms.dto.response.UserRespDto;
import com.dog.modules.upms.feign.UserClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/test")
public class TestController {


   @Autowired
   private UserClient userClient;


    @Autowired
    private AccessLogClient accessLogClient;




    @GetMapping("/hello")
    public String hello(){
        System.out.println("===============hello world===========");
        return "hello world system service";
    }

    @PostMapping(value = "/user/add")
    UserRespDto add(@RequestBody UserReqDto userReqDto){
      log.info("远程调用服务upms-biz-service，请求参数{}", JSON.toJSONString(userReqDto));
      UserRespDto userRespDto  =  userClient.add(userReqDto);
      log.info("远程调用服务upms-biz-service，返回结果{}",JSON.toJSONString(userRespDto));
      userRespDto.setMessage("服务system-biz-service返回结果");
      return  userRespDto;
    }



    @PostMapping(value = "/infra/log")
    Boolean log(@RequestBody AccessLogCreateReqDTO accessLogCreateReqDTO){
        log.info("远程调用服务infra-biz-service，请求参数{}", JSON.toJSONString(accessLogCreateReqDTO));
        accessLogClient.createAccessLog(accessLogCreateReqDTO);
        log.info("远程调用服务infra-biz-service，返回结果{}",JSON.toJSONString(1));
        return  Boolean.TRUE;
    }

}
